<?php
define('SW_',true);
require_once('_common.php');

//判断用户登录
SWAdmin::checkLogin(true,true);

//创建附件对象
$objAttr=new SWAttachment();

//如果是data:image这类的上传
if($imageUrls = SW::request('urls','post')){

	echo $objAttr->saveImage($imageUrls);

//如果是传统上传框上传
}else{

	$res=$objAttr->upload();

	//成功，发送响应
	if($res){

		header('Content-type: text/html; charset=UTF-8');
		echo json_encode(array('error' => 0, 'url' => $res['url'], 'size'=> $res['size'], 'path'=>$res['path'], 'name'=>$res['name']));

	//发送错误响应代码
	}else{

		header('Content-type: text/html; charset=UTF-8');
		echo json_encode(array('error' => 1, 'message' => LANG('Upload_Error')));
		
	}

}

?>
